package com.jiangruan.javaproject.utils;
/**
 * @author:xulonghua
 * @email:3162193565@qq.com desc:
 * datatime 2021/12/20 23:25
 */

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Security;

/**
 *@author:xulonghua
 *@email:3162193565@qq.com
 *desc:该类用于实现各种hash算法
 *datetime 2021/12/20 23:25
 */
public class Hash {
    /**
     * 使用SHA256算法对给定的数据进行sha256计算
     * @param date
     * @return 哈希值
     */

    public  static byte[]  SHA256(byte[]date){
        try {
            MessageDigest digest=MessageDigest.getInstance ( "SHA-256" );
            digest.update ( date );
           return digest.digest ();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace ();
        }
        return null;
    }
    public static  byte[] PRPEMD160(byte[] data){
        /**
         * 使用ripemd160算法对数据进行哈希计算，并返回哈希结果哦
         * @param data 给定的数据
         * @return ripemd160
         */

        Security.addProvider ( new BouncyCastleProvider () );
        try {
            MessageDigest digest=MessageDigest.getInstance ( "RipeMD160" );
            digest.update ( data );
            return digest.digest ();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace ();
        }
        return null;
    }
}
